const baseUrl = "../images/";
var fs = require('fs');
var imgHash = require('./imghash1.js');
var cs = fs.readdirSync(baseUrl);

function runHash(cs, sig) {
	if(sig == cs.length) return;
	console.log(cs[i] + "=============" + sig);
	var cname = cs[sig];
	var imgArr = fs.readdirSync(baseUrl + cname);
	var obj = {};
	for(var i = 0; i < imgArr.length; i++) {
		if(!obj.hasOwnProperty(imgArr[i])) {
			var imgUrl = "../images/" + cname + "/" + imgArr[i];
			var hash2 = imgHash.hash(imgUrl);
			obj[imgArr[i]] = hash2;
		}
		console.log(hash2);
	}
	var t = JSON.stringify(obj);
	console.log(cname + "Wrting...");
	fs.writeFileSync("../images_hash/" + cname + ".json", t);
	runHash(cs, sig + 1);
}
runHash(cs, 0);